package com.icinfo.cloud.provider.punish.config.enums;

import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.PartyTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 自由裁量规则（违法情形配置）配置类型
 *
 * @author Junfeng.Chen
 * @date 2024/1/31 8:52
 **/
@Getter
@AllArgsConstructor
public enum DiscretionRuleApplyTypeEnum {
    /**
     * 个人
     */
    PERSONAL("1", "个人"),
    /**
     * 单位
     */
    ORG("2", "单位"),
    ;

    /**
     * 编码
     */
    private final String code;
    /**
     * 描述
     */
    private final String desc;

    /**
     * 根据code获取枚举
     *
     * @param code
     * @return
     */
    public static DiscretionRuleApplyTypeEnum getByCode(String code) {
        for (DiscretionRuleApplyTypeEnum e : DiscretionRuleApplyTypeEnum.values()) {
            if (e.getCode().equals(code)) {
                return e;
            }
        }
        throw new BusinessException("转换枚举异常");
    }


    /**
     * 根据当事人类型转换为自由裁量适用范围
     *
     * @param partyType 当事人类型
     * @return 适用范围类型
     */
    public static DiscretionRuleApplyTypeEnum convertByPartyType(PartyTypeEnum partyType) {
        if (Objects.isNull(partyType)) {
            return null;
        }
        return PartyTypeEnum.PERSON.equals(partyType) ? PERSONAL : ORG;
    }

}
